/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoHashTest.go			*/
/********************************************************/

package main

import (
	. "GoGlb"
	C "GoCap"
)

type GoHsDt struct {
	key	string
	val	string
}

func main() {
	hash := new(C.GoHash)
	src1 := "Copyright (C) 2016 Gong Li Bin		"

	hash.GoHashInit(C.GoBkt[6])

	/* string */
	bkt := hash.GoHashBkt()
	fun1 := hash.GoHashFunc(src1)
	GoPrint("%d MOD %d = %d\n", fun1, bkt, fun1 % bkt)

	GoPrtln("src1:", src1)
	hash.GoHashInto(fun1, src1)

	dst1 := hash.GoHashFrom(fun1)
	GoPrtln("dst2:", dst1)

	/* struct */
	src2 := &GoHsDt{"This_Is_GoHsDt_Key", "This_Is_GoHsDt_Val"}

	fun2 := hash.GoHashFunc(src2.key)
	GoPrint("\n%d MOD %d = %d\n", fun2, bkt, fun2 % bkt)

	hash.GoHashInto(fun2, src2)
	GoPrint("src2.key: %s, src2.val: %s\n", src2.key, src2.val)

	dst2 := (hash.GoHashFrom(fun2)).(*GoHsDt)
	GoPrint("dst2.key: %s, dst2.val: %s\n\n", dst2.key, dst2.val)

	show(dst1)
	show(dst2)
}

func show(v interface{}) {
	switch v.(type) {
		case string:
			GoPrint("Show -> String: %s\n", v)
		case *GoHsDt:
			GoPrint("Show -> Dst.Key: %s, Dst.Val: %s\n", v.(*GoHsDt).key, v.(*GoHsDt).val)
		default:
			GoPrint("Show -> Unknown type\n")
	}
}
